package com.quktzhuanka.app.activity;

import android.net.Uri;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.quktzhuanka.app.R;
import com.quktzhuanka.app.base.BaseActivity;
import com.quktzhuanka.app.bean.BannerBean;
import com.quktzhuanka.app.bean.Response;
import com.quktzhuanka.app.config.Constants;
import com.quktzhuanka.app.https.HttpUtils;
import com.quktzhuanka.app.https.onOKJsonHttpResponseHandler;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cz.msebera.android.httpclient.Header;

public class DiTuiImgActivity extends BaseActivity {
    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.img_top)
    ImageView img_top;

    private List<BannerBean> images = new ArrayList<>();

    @Override
    protected void initUI() {
        setContentView(R.layout.activity_ditui);
        ButterKnife.bind(this);

    }

    @Override
    protected void initData() {
        tvLeft.setVisibility(View.VISIBLE);
        tvTitle.setText("地推物料");
        getDiTui();
    }

    @Override
    protected void initListener() {

    }
    // 地推物料
    private void getDiTui(){
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 9);
        HttpUtils.post(Constants.GET_BANNER, requestParams, new onOKJsonHttpResponseHandler<BannerBean>(new TypeToken<Response<BannerBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

            }

            @Override
            public void onSuccess(int statusCode, Response<BannerBean> datas) {
                if (datas.isSuccess()) {
                    images.clear();
                    images.addAll(datas.getData().getList());
                    String ss = Constants.APP_IP+images.get(0).getImg();
                    Glide.with(DiTuiImgActivity.this).load(Constants.APP_IP + images.get(0).getImg()).dontAnimate().into(img_top);
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
//        RequestParams requestParams = new RequestParams();
//        HttpUtils.post(Constants.GET_KEFU, requestParams, new TextHttpResponseHandler() {
//            @Override
//            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(responseString);
//            }
//
//            @Override
//            public void onFinish() {
//                super.onFinish();
//            }
//
//            @Override
//            public void onStart() {
//                super.onStart();
//            }
//
//            @Override
//            public void onSuccess(int statusCode, Header[] headers, String responseString) {
//                if (getComeActivity().isDestroyed())
//                    return;
//                try {
//                    if (new JSONObject(responseString).getInt("code") != 0) {
//                        T.showShort(DiTuiImgActivity.this, new JSONObject(responseString).getString("msg"));
//                        return;
//                    }
//                    JSONObject object = new JSONObject(responseString).getJSONObject("data");
//                    phone.setText(object.getString("weixin"));
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//            }
//        });
    }

}
